home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #2 / Ham Radio 2000 - Volume 2.iso / HAMV2 / TCP_IP / TNOS230S / PUSHMAIL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1997-07-30  |  1.7 KB  |  66 lines

  1. /* This program allows you to push mail destined for one host
  2.  * to another (i.e. going on vacation and shutting down your
  3.  * host but want your mail delivered by your "buddy"):
  4.  */
  5. #include <stdio.h>
  6. #ifdef MSDOS
  7. #include <dir.h>
  8. #include <dos.h>
  9. #endif
  10. #ifndef _lint
  11. #include <stdlib.h>
  12. #endif
  13. #include <fcntl.h>
  14. #include <string.h>
  15. #define MAXLINE 256
  16.  
  17. #if !defined(_lint)
  18. static char rcsid[] OPTIONAL = "$Id: pushmail.c,v 1.9 1997/07/31 00:44:20 root Exp root $";
  19. #endif
  20.  
  21. main(int argc,char *argv[])
  22. {
  23.     struct ffblk block;
  24.     int done,i;
  25.     FILE *fd,*fo;
  26.     char *j,str[MAXLINE+2],*strp;
  27.     
  28.     fprintf(stderr,"\n%s is COPYRIGHT 1989 by John D. Hays (KD7UW)\n",argv[0]);
  29.     fprintf(stderr,"Authorized for unlimited distribution for ");
  30.     fprintf(stderr,"Amateur Radio Use\n");
  31.     fprintf(stderr,"This notice must be retained.  All Rights Reserved.\n\n");
  32.     if (argc < 3)
  33.     {
  34.         fprintf(stderr,"Usage: %s oldhost forwardhost \007\n",argv[0]);
  35.         exit(0);
  36.     }
  37.     
  38.     done = findfirst("*.wrk",&block,0x3F);
  39.  
  40.     while (!done) {
  41.         if ((fd = fopen(block.ff_name,"r")) != NULL)
  42.         strp = str; /* Turbo-C is not handling fgets right ??? */
  43.         {
  44.             strp = fgets(strp,MAXLINE,fd);
  45.             j = strrchr(strp,'\n');
  46.             if (j != NULL) *j = '\0';
  47.             if (stricmp(argv[1],strp) == 0)
  48.             {
  49.                 fprintf(stderr,"Changing: %s\n",block.ff_name);
  50.                 i = unlink(block.ff_name);
  51.                 fo = fopen(block.ff_name,"w");
  52.                 fprintf(fo,"%s\n",argv[2]);
  53.                 while ((strp = fgets(strp,MAXLINE,fd)) != NULL)
  54.                 {
  55.                     fprintf(fo,"%s",strp);
  56.                 }
  57.             }
  58.             fclose(fd);
  59.             fclose(fo);
  60.         }
  61.         fprintf(stderr, "%s: Unable to open %s\n",argv[0],block.ff_name);
  62.         done = findnext(&block);
  63.     }
  64. }
  65.  
  66.